package com.ysxsoft.wdg.ui.activity.my;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.base.BaseActivity;
import com.ysxsoft.wdg.bean.BaseBean;
import com.ysxsoft.wdg.net.CallbackCode;
import com.ysxsoft.wdg.util.ToastUtils;
import com.ysxsoft.wdg.util.ViewUtils;
import com.ysxsoft.wdg.util.sp.SharePrefUtils;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class YjfkActivity extends BaseActivity {


    public static void start(Context context){
        Intent intent = new Intent(context, YjfkActivity.class);
        context.startActivity(intent);
    }


    @BindView(R.id.topView)
    View topView;
    @BindView(R.id.title_content)
    TextView titleContent;
    @BindView(R.id.et_input)
    EditText etInput;

    private String uid = "";

    @Override
    protected int getLayoutId() {
        return R.layout.activity_yjfk;
    }

    @Override
    protected void initData() {
        initStatusBar(topView,false);
        titleContent.setText("意见反馈");

        uid = SharePrefUtils.getUserId();


    }

    @Override
    protected void setListener() {

    }


    @OnClick({R.id.title_finish, R.id.btn_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.title_finish:
                finish();
                break;
            case R.id.btn_sure:
                String content = etInput.getText().toString().trim();
                if (TextUtils.isEmpty(content )){
                    ToastUtils.showToast("请输入您的意见");
                    return;
                }

                mApiHelper.postYjfk(uid, content, new Observer<BaseBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(BaseBean baseBean) {
                        ToastUtils.showToast(baseBean.getMs());
                        if (baseBean.getCode().equals(CallbackCode.SUCCESS)){
                            finish();
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        ToastUtils.showToast("请稍后再试");
                    }

                    @Override
                    public void onComplete() {

                    }
                });
                break;
        }
    }


    @Override
    protected void onPause() {
        super.onPause();
        ViewUtils.closeKeyboard(this);
    }
}
